﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace TestBat.Views.Converters
{
    [ValueConversion(typeof(int), typeof(string))]
    public class NullPercentage2StringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return "N.A.";
            return Double.Parse(value.ToString()).ToString("#0.00") + " %";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value.Equals("N.A."))
                return null;
            return int.Parse(value.ToString());
        }
    }
}
